<%@page import="br.com.ufpb.halloc.negocio.Professor"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.util.Collections"%>
<%@page import="javax.swing.JOptionPane"%>
<%@page import="br.com.ufpb.halloc.comunicacao.Facade"%>
<%@page import="java.util.ArrayList"%>
<%@page import="br.com.ufpb.halloc.negocio.Disciplina"%>
<%@page import="br.com.ufpb.halloc.negocio.Turma"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <style type="text/css">
            div#back {
                background-color: lightsteelblue;
                height: auto;
                margin-top: 0px;
                margin-left: 170px;
                margin-right: 170px;
            }
            div#form {
                background-color: #DDD;
                font: 14px Verdana, sans-serif;
                height: 60px;
                margin-top: 5px;
                border: 1px solid #696969;
                margin-left: 100px;
                margin-right: 100px;
            }

            div#campos, div#form {
                color: #333;
            }

            #tab_customizada
            {
                font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
                width:100%;
                border-collapse:collapse;
            }
            #tab_customizada td, #tab_customizada th 
            {
                font: 14px Verdana, sans-serif;
                border:2px solid #98bf21;
                padding:3px 7px 2px 7px;
                color: #000000;
            }
            #tab_customizada th 
            {
                font: 16px Verdana, sans-serif;
                text-align:center;
                padding-top:5px;
                padding-bottom:4px;
                background-color:#369;
                color:#fff;
            }
            #tab_customizada tr.alt td 
            {
                color:#000000;
                background-color: #EAF2D3;
            }

        </style>

    </head>
    <body>
        <jsp:include page="menubarra.jsp"></jsp:include>        
        <br>

        <div id="back">
            <br>
            <% Facade f = Facade.getInstance();
                Professor p = f.buscarProfessorPorMatricula(request.getParameter("matricula"));

            %>
            <div align="center"><b>Alocar Disciplina para <%=p.getNome()%></b></div>
            <br></br>
            
            <div align="center">
                <h4 align="center">${mensagem}</h4>
                <br></br>
                <table  id="tab_customizada" border="1">
                    <tr> 
                        <th> Disciplinas de preferência:</th>
                    </tr>    
                    <% List<Disciplina> l = (List<Disciplina>) request.getAttribute("preferencias");
                        if (!l.isEmpty()) {
                            for (Disciplina d : l) {%>
                                <tr>
                                        <td align="center"> <%=d.getNome()%> </td>
                                </tr>
                                

                    <% }
                        } else {
                            out.println("Ainda não escolhi minhas disciplinas preferidas.");
                        }

                    %>
                </table>
                <br>
                <br>

                <table id="tab_customizada" border="1">
                    <th colspan="4">Turmas com as Disciplinas Preferidas Disponiveis</th>
                    <tr>
                        <th>Curso</th>
                        <th align="center" >Nome da Turma</th>
                        <th align="center" >Disciplina</th>
                        <th align="center" >Alocar?</th>
                        
                    </tr>
                    <%
                        List<Turma> m = (List<Turma>) request.getAttribute("ministra");
                        for (Turma min : m) {%>
                   <tr>
                                <td align="center" > <%= f.pesquisarCursoPorId(min.getNrCurso()).getNome()%></td>
                                <td align="center" > <%=min.getNomeTurma()%></td>
                                <td align="center" > <%=f.pesquisaDisciplinaPorIDNoBD(min.getCodDisciplina()).getNome()%></td>
                                <td align="center" > <a href="AlocarProfessorADisciplina?professor=<%=p.getMatricula()%>&turma=<%=min.getCodTurma()%>">Alocar</a>   </td>
                            </tr>
                    <% }

                    %></td>

                </table>
                <br>
                <br>
            </div>
           
            <div align="center">
                <table id="tab_customizada" border="1">
                    <tr>
                         <th colspan="4">Turmas disponíveis para alocar:</th>
                        
                    </tr>
                    
                    <tr>
                        <th>Curso</th>
                        <th align="center" >Nome da Turma</th>
                        <th align="center" >Disciplina</th>
                        <th align="center" >Alocar?</th>
                        
                    </tr>
                    <% //buscar disciplinas cadastradas
                        List<Turma> minist = f.turmasAbertas();


                        if (minist != null) {
                            for (Turma mini : minist) { %>
                            <tr>
                                <td align="center" > <%= f.pesquisarCursoPorId(mini.getNrCurso()).getNome()%></td>
                                <td align="center" > <%=mini.getNomeTurma()%></td>
                                <td align="center" > <%=f.pesquisaDisciplinaPorIDNoBD(mini.getCodDisciplina()).getNome()%></td>
                                <td align="center" > <a href="AlocarProfessorADisciplina?professor=<%=p.getMatricula()%>&turma=<%=mini.getCodTurma()%>">Alocar</a>   </td>
                            </tr>
                    <%
                            }
                        }
                    %>  
                </table>
                <br>
                </body>
                </html>
